package viper.badRelays;

import java.util.Hashtable;

import javax.swing.JLabel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


/**
 *
 * @author Kevin Sin
 * 
 * Revision number: 1
 * Date created: 1/17/10
 * Date of Last Back-up on SVN: none
 * 
 * <p>JPanel for when user first logs in.  Displays the peers online.
 */
public class RelaysPanel extends javax.swing.JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form LoggedInJPanel */
	public RelaysPanel() {
		initComponents();
	}

	private javax.swing.JButton jButton1; //Logout button
	private javax.swing.JLabel jLabel1; //delay
	private javax.swing.JLabel jLabel2; //drop rate 1
	private javax.swing.JLabel jLabel3; //drop rate 2
	private javax.swing.JSlider jSlider1; //delay
	private javax.swing.JSlider jSlider2; //drop rate 1
	private javax.swing.JSlider jSlider3; //drop rate 2

	/** This method is called from within the constructor to
	 * initialize the form.
	 */
	private void initComponents() {

		jButton1 = new javax.swing.JButton();

		jButton1.setText("Log out");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();

		jSlider1 = new javax.swing.JSlider();
		jSlider2 = new javax.swing.JSlider();
		jSlider3 = new javax.swing.JSlider();

		Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
		labelTable.put( new Integer(0), new JLabel("0") );
		labelTable.put( new Integer(1000), new JLabel("1000") );
		jSlider1.setLabelTable(labelTable);
		jSlider1.setPaintLabels(true);
		jSlider1.setMinimum(0);
		jSlider1.setMaximum(1000);
		jSlider1.setMajorTickSpacing(100);
		jSlider1.setValue(0);
		jSlider1.setToolTipText("Current value: 0ms");
		jSlider1.addChangeListener(new ChangeListener() {	
			@Override
			public void stateChanged(ChangeEvent e) {
				int del = jSlider1.getValue();
				BadRelaysStateManager.INSTANCE.setDelay(del);
				jSlider1.setToolTipText("Current value: " + del + "ms");
			}
		});
		jSlider1.setPaintTicks(true);
		
		Hashtable<Integer, JLabel> labelTable2 = new Hashtable<Integer, JLabel>();
		labelTable2.put( new Integer(0), new JLabel("0") );
		labelTable2.put( new Integer(1000), new JLabel("1") );
		jSlider2.setLabelTable(labelTable2);
		jSlider2.setPaintLabels(true);
		jSlider2.setMinimum(0);
		jSlider2.setMaximum(1000);
		jSlider2.setMajorTickSpacing(100);
		jSlider2.setValue(0);
		jSlider2.setToolTipText("Current value: 0");
		jSlider2.addChangeListener(new ChangeListener() {	
			@Override
			public void stateChanged(ChangeEvent e) {
				double dr1 = jSlider2.getValue()/1000.0;
				BadRelaysStateManager.INSTANCE.setDrop_Rate_Hi(dr1);
				jSlider2.setToolTipText("Current value: " + dr1);
			}
		});
		
		jSlider2.setPaintTicks(true);
		

		Hashtable<Integer, JLabel> labelTable3 = new Hashtable<Integer, JLabel>();
		labelTable3.put( new Integer(0), new JLabel("0") );
		labelTable3.put( new Integer(1000), new JLabel("1") );
		jSlider3.setLabelTable(labelTable3);
		jSlider3.setPaintLabels(true);
		jSlider3.setMinimum(0);
		jSlider3.setMaximum(1000);
		jSlider3.setMajorTickSpacing(100);
		jSlider3.setValue(0);
		jSlider3.setToolTipText("Current value: 0");
		jSlider3.addChangeListener(new ChangeListener() {	
			@Override
			public void stateChanged(ChangeEvent e) {
				double dr2 = jSlider3.getValue()/1000.0;
				BadRelaysStateManager.INSTANCE.setTransition_Rate_toHi(dr2);
				jSlider3.setToolTipText("Current value: " + dr2);
			}
		});
		jSlider3.setPaintTicks(true);
		
		jLabel1.setText("Delay (ms):");

		jLabel2.setText("Drop Rate:");

		jLabel3.setText("Transition Rate:");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addContainerGap()
						//.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
								.addGroup(layout.createSequentialGroup()
										.addGap(29, 29, 29)
										.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(layout.createSequentialGroup()
														.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
														.addGap(370, 370, 370)
														.addComponent(jButton1))
														.addGap(20, 20, 20)
														.addGroup(layout.createSequentialGroup()
																.addGap(7, 7, 7)
																.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
																		.addComponent(jLabel1)
																		.addComponent(jLabel2)
																		.addComponent(jLabel3))
																		.addGap(25, 25, 25)
																		.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(jSlider1, 350, 350, 350)
																				.addComponent(jSlider2, 350, 350, 350)
																				.addComponent(jSlider3, 350, 350, 350))
																				.addContainerGap(12, Short.MAX_VALUE))
		))));
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jButton1)
								.addGap(38, 38, 38)))
								.addGroup(layout.createSequentialGroup()
										.addGap(63, 63, 63)
										.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(jLabel1)
												.addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGap(50, 50, 50)
												.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel2)
														.addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGap(50, 50, 50)
														.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
																.addComponent(jLabel3)
																.addComponent(jSlider3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
																.addContainerGap(44, Short.MAX_VALUE))
		);
		
	}// </editor-fold>

	/**
	 * @param evt
	 * Logout button pressed
	 */
	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		BadRelaysStateManager.INSTANCE.logout();
	}

	/**
	 * Updates the peers to display.
	 */
	public void update(){
	}

}
